package com.xdap.Controller;

import com.definesys.mpaas.common.http.Response;
import com.xdap.service.JmReportExportService;
import com.xdap.service.JmReportImportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 积木报表-设置默认首页跳转
 */
@RestController
@Api(tags = "导入导出操作")
@RequestMapping("/jimureport")
public class JmReportIndexController {

    @Autowired
    private JmReportExportService exportService;
    @Autowired
    private JmReportImportService importService;

    @ApiOperation(value = "export")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "...", required = true, dataType = "String", paramType = "query")
    })
    @GetMapping("/export")
    public void index(HttpServletResponse httpServletResponse,@RequestParam String name) throws Exception {
        exportService.export(httpServletResponse,name);
    }
    @PostMapping("/import")
    public Response file(@RequestParam("files") List<MultipartFile> files) {
        Map<String, String> data = importService.insertData(files);

        return Response.ok().data(data);
    }
}